package com.example.system.web;

import com.example.common.core.Result;
import com.example.system.annotation.HasPermission;
import com.example.system.dto.RoleParam;
import com.example.system.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(value = "角色API", tags = "角色API")
@RestController
@RequestMapping("/system/api/role")
public class RoleController {
    @Resource
    private RoleService roleService;

    @HasPermission("system:role:add")
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/add")
    public Result add(@RequestBody RoleParam roleParam) {
        return roleService.add(roleParam);
    }

    @HasPermission("system:role:delete")
    @ApiOperation(value = "删除", notes = "删除")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        return roleService.delete(id);
    }

    @HasPermission("system:role:delete")
    @ApiOperation(value = "批量删除", notes = "批量删除")
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestParam(value = "ids") List<Integer> ids) {
        return roleService.deleteBatch(ids);
    }

    @HasPermission("system:role:update")
    @ApiOperation(value = "更新", notes = "更新")
    @PutMapping("/update")
    public Result update(@RequestBody RoleParam roleParam) {
        return roleService.update(roleParam);
    }

    @HasPermission("system:role:select")
    @ApiOperation(value = "查询", notes = "查询")
    @GetMapping("/{id}")
    public Result select(@PathVariable("id") Integer id) {
        return roleService.select(id);
    }

    @HasPermission("system:role:selectList")
    @ApiOperation(value = "查询列表", notes = "查询列表")
    @GetMapping("/selectList")
    public Result selectList(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        return roleService.selectList(page, size);
    }

    @HasPermission("system:admin:select")
    @ApiOperation(value = "根据管理员ID查询对应角色", notes = "根据管理员ID查询对应角色")
    @GetMapping("/selectRolesByAdminId/{id}")
    public Result selectRolesByAdminId(@PathVariable("id") Integer id) {
        return roleService.selectRolesByAdminId(id);
    }
}
